package com.ruoyi.finance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.finance.domain.KltPurchaseBatch;
import com.ruoyi.finance.mapper.KltSalesOrderDao;
import com.ruoyi.finance.domain.KltSalesOrder;
import com.ruoyi.finance.service.KltSalesOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * (KltSalesOrder)表服务实现类
 *
 * @author makejava
 * @since 2024-12-19 12:18:03
 */
@Service("kltSalesOrderService")
public class KltSalesOrderServiceImpl extends ServiceImpl<KltSalesOrderDao, KltSalesOrder> implements KltSalesOrderService {

    @Resource
    private KltSalesOrderDao kltSalesOrderDao;

    @Override
    public List<KltSalesOrder> getAllKltSalesOrder(QueryWrapper<KltSalesOrder> kltPurchaseBatchQueryWrapper) {

        List<KltSalesOrder> KltSalesOrder = kltSalesOrderDao.selectList(kltPurchaseBatchQueryWrapper);
        return  KltSalesOrder;
    }

    @Override
    public Boolean updateSalesOrderIsDel(List<Long> ids) {

        for (Long id : ids) {
            KltSalesOrder kltSalesOrder = new KltSalesOrder();
            kltSalesOrder.setSalesOrderId(Math.toIntExact(id));
            kltSalesOrder.setIsDel("1");
            int i = kltSalesOrderDao.updateById(kltSalesOrder);
            if (i==0){
                return false;
            }
        }
        return true;

    }


    @Override
    public Integer getMaxId() {
        QueryWrapper<KltSalesOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("sales_order_id ").last("LIMIT 1");
        List<KltSalesOrder> PurchaseBatch = kltSalesOrderDao.selectList(queryWrapper);
        if (PurchaseBatch.isEmpty()) {
            return null; // 如果没有找到任何记录，则返回null或根据需要返回其他默认值
        }
        return PurchaseBatch.get(0).getSalesOrderId();
    }
    public List<String> selectAllCustomerName() {
        return kltSalesOrderDao.selectAllCustomerName();
    }
}

